package com.fr.report.io;

import com.fr.base.background.ColorBackground;
import com.fr.base.core.FRCoreContext;
import com.fr.report.PageSet;
import com.fr.report.PageSetChain;
import com.fr.report.ReportPage;
import com.fr.report.ResultWorkBook;
import com.fr.report.core.ReportUtils;
import com.fr.report.painter.PagePainter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.Rectangle2D.Double;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import org.freehep.graphicsio.swf.SWFGraphics2D;

public class SWFExporter extends AbstractAppExporter
{
  private static final Object lock = new Object();

  public void export(OutputStream paramOutputStream, ResultWorkBook paramResultWorkBook)
    throws Exception
  {
    PageSet localPageSet = paramResultWorkBook.generateReportPageSet(ReportUtils.getPaperSettingListFromWorkBook(paramResultWorkBook)).getTraversingCase();
    export(paramOutputStream, localPageSet);
    localPageSet.release();
  }

  public void export(OutputStream paramOutputStream, PageSet paramPageSet)
    throws Exception
  {
    if ((paramOutputStream == null) || (paramPageSet == null))
      return;
    int i = 0;
    int j = 0;
    ArrayList localArrayList = new ArrayList();
    FRCoreContext.TMAP.put(Thread.currentThread(), Boolean.TRUE);
    double d = 0.75D;
    for (int k = 0; k < paramPageSet.size(); ++k)
    {
      ReportPage localReportPage1 = paramPageSet.getPage(k);
      if (localReportPage1 == null)
        break;
      i = Math.max(i, (int)(localReportPage1.getPageWidth() * d));
      j = (int)(j + localReportPage1.getPageHeight() * d);
      localArrayList.add(localReportPage1);
    }
    SWFGraphics2D localSWFGraphics2D = new SWFGraphics2D(paramOutputStream, new Dimension(i, j));
    localSWFGraphics2D.startExport();
    ColorBackground.getInstance(Color.white).paint(localSWFGraphics2D, new Rectangle2D.Double(0.0D, 0.0D, i, j));
    int l = 0;
    int i1 = 0;
    int i2 = localArrayList.size();
    while (i1 < i2)
    {
      ReportPage localReportPage2 = (ReportPage)localArrayList.get(i1);
      localSWFGraphics2D.translate(0, l);
      synchronized (lock)
      {
        new PagePainter(localReportPage2, localSWFGraphics2D, true).convert();
      }
      localSWFGraphics2D.translate(0, -l);
      l = (int)(l + localReportPage2.getPageHeight() * d);
      ++i1;
    }
    localSWFGraphics2D.endExport();
    FRCoreContext.TMAP.remove(Thread.currentThread());
  }
}